<!-- <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .box{
            width: 300px;
            height: 400px;
            background-color:#9e2c2b;
            margin: auto;
            padding: 10px;
        }
        p,h4,h2{
            text-align: center;
            width: 100%;
            color: white;
        }
        p:nth-child(2){
            margin-bottom: 30px;
            font-size: 30px;
        }
        h4{
            font-size: 30px;
            display: flex;
            justify-content: center;
        }
        .box  div{
            width: 50px;
            height: 50px;
            line-height: 50px;
            background-color: black;
            margin: 0px 10px;
            margin-bottom: 50px;
        }
       
    </style>
</head>
<body>
    <div class="box">
        <p></p>
        <p>下班倒计时</p>
        <h4>
            <div></div>
            <div></div>
            <div></div>
        </h4>
        <h2>23：00：00下班</h2>
    </div>
    
    <script>
        function fn(){
            const p = document.querySelectorAll('p')
            const date = new Date()
            // 获取将来时间
            const last = +new Date('2025-11-13 23:00:00')
            //现在时间
            const now= +new Date()
            //剩余时间
            const time = (last - now)/1000
            p[0].innerHTML = `今天是${date.getFullYear()}年${date.getMonth()}月${date.getDate()}日`
            let h = parseInt(time/60/60%24)
            h = h<10?'0'+h : h
            let f = parseInt(time/60%60)
            f = f<10?'0'+f : f
            let m = parseInt(time%60)
            m = m<10?'0'+m : m
            const divv = document.querySelectorAll('h4 div')
            divv[0].innerHTML = h
            divv[1].innerHTML = f
            divv[2].innerHTML = m
        }
        fn()
        setInterval(fn,1000)
    </script>
</body>
</html> -->










<!-- 复习版  -->
 <!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }

        .box{
            width: 300px;
            height: 400px;
            background-color: #9e2c2b;
            color: white;
            text-align: center;
            padding: 10px 0px;
        }
        
        h1{
            margin: 20px 0px;
        }

        ul{
            list-style: none;
            display: flex;
            justify-content: center;
            height: 40px;
            line-height: 40px;
            margin-bottom: 40px;
        }

        ul li{
            width: 40px;
            font-size:30px;
            background-color: black;
        }

    </style>
 </head>
 <body>
    
    <div class="box">
        <p>今天是2222年2月22日</p>
        <h1>下班倒计时</h1>
        <ul>
            <li>1</li>:
            <li>2</li>:
            <li>3</li>
        </ul>
        <h3>17:30:00下课</h3>
    </div>


    <script>


        // 定义函数 fn 
        function fn(){
            const date = new Date()
            // console.log(date)
            const newdate = new Date('2025-11-18 17:30:00')
            let time = (newdate-date)/1000
            console.log(time)
            
            // 获取小时 并且进行 '补零'
            let h = parseInt(time/60/60%24)
            h = h<10? '0'+h : h
            // 获取分钟
            let m = parseInt(time/60%60)
            m = m<10? '0'+m : m
            //获取秒
            let s = parseInt(time%60)
            s = s<10? '0'+s : s


            //将 时分秒 插入 倒计时中
            const lis = document.querySelectorAll('ul li')
            lis[0].innerHTML = h
            lis[1].innerHTML = m
            lis[2].innerHTML = s
        }
         fn()   
         
         //添加定时器
         setInterval(fn,1000)
    </script>

 </body>
 </html> 